<template>
    <div class="achieveBasicInfo container">
        <div id="components-form-demo-advanced-search">
            <div class="tabCommonTitle">
                <span>专利基本信息</span>
                <b>红色星号为必填项</b>
            </div>
            <a-form-model
                ref="ruleForm"
                :model="form"
                :rules="rules"
                :label-col="labelCol"
                :wrapper-col="wrapperCol"
            >
                <a-form-model-item ref="patentNumber" label="专利号：" prop="patentNumber">
                    <a-input v-model="form.patentNumber" @blur="() => {$refs.patentNumber.onFieldBlur();}"/>
                </a-form-model-item>
                <a-form-model-item ref="patentName" label="专利名称：" prop="patentName">
                    <a-input v-model="form.patentName" @blur="() => {$refs.patentName.onFieldBlur();}"/>
                </a-form-model-item>
                <a-form-model-item ref="patentee" label="专利权人：" prop="patentee">
                    <a-input v-model="form.patentee" @blur="() => {$refs.patentee.onFieldBlur();}"/>
                </a-form-model-item>
                <a-form-model-item ref="inventor" label="发明人：" prop="inventor">
                    <a-input v-model="form.inventor" @blur="() => {$refs.inventor.onFieldBlur();}"/>
                </a-form-model-item>
                <a-form-model-item ref="IPCClassNo" label=" IPC分类号：" prop="IPCClassNo">
                    <a-input v-model="form.IPCClassNo" @blur="() => {$refs.IPCClassNo.onFieldBlur();}"/>
                </a-form-model-item>
                <a-form-model-item>
                    <a-button class="save_info_btn" :class="is_modify=='Y'?'':'disabled'" :disabled="is_modify=='Y'?false:true" type="primary" @click="onSubmit">保存</a-button>
                </a-form-model-item>
            </a-form-model>
        </div>
    </div>
</template>
<script>
import {
    // 添加或修改
    zlsbZlAdd,
    // 详情
    zlsbGetZl
} from "@/api/shenbao";
export default {
    props: ['is_modify'],
    data() {
        return {
            labelCol: { span: 2 },
            wrapperCol: { span: 7 },
            other: '',
            form: {
                // 专利号
                patentNumber: '',
                // 专利名称
                patentName: '',
                // 专利权人
                patentee: '',
                // 发明人
                inventor: '',
                // IPC分类号
                IPCClassNo: ''
            },
            rules: {
                patentNumber: [
                    { required: true, message: '请填写专利号', trigger: 'blur' }
                ],
                patentName:[
                    { required: true, message: '请填写专利名称', trigger: 'blur' }
                ],
                patentee:[
                    { required: true, message: '请填写专利权人', trigger: 'blur' }
                ],
                inventor:[
                    { required: true, message: '请填写专利权人', trigger: 'blur' }
                ],
                IPCClassNo:[
                    { required: true, message: '请填写IPC分类号', trigger: 'blur' }
                ]
            },
            detailInfo: {}
        }
    },
    mounted(){
        this.getDetailInfo();
    },
    methods: {
        getDetailInfo(){
            zlsbGetZl({
                cxj_cxj_id: this.$route.query.cxj_cxj_id
            }).then(res=>{
                let data = res.data;
                if (data.success) {
                    this.detailInfo = data.result;
                    if (data.result) {
                        this.form.patentNumber = data.result.zlZlh;
                        this.form.patentName = data.result.zlZlmc;
                        this.form.patentee = data.result.zlZlqr;
                        this.form.inventor = data.result.zlFmr;
                        this.form.IPCClassNo = data.result.zlIpc;
                    }
                } else {
                    this.$message.error(data.message)
                }
            })
        },
        onSubmit() {
            let that = this;
            this.$refs.ruleForm.validate(valid => {
                if (valid) {
                    let formData = new FormData();
                    formData.append('cxj_cxj_id', that.$route.query.cxj_cxj_id)
                    formData.append('zlZlh', that.form.patentNumber)
                    formData.append('zlZlmc', that.form.patentName)
                    formData.append('zlZlqr', that.form.patentee)
                    formData.append('zlFmr', that.form.inventor)
                    formData.append('zlIpc', that.form.IPCClassNo)
                    if (that.detailInfo && that.detailInfo.id) {
                        formData.append('id', that.detailInfo.id)
                    } else {
                        formData.append('id', '')
                    }
                    zlsbZlAdd(formData).then(res=>{
                        let data = res.data;
                        if (data.success) {
                            that.$message.success('保存成功')
                            that.getDetailInfo();
                        } else {
                            that.$message.error(data.message)
                        }
                    })
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        }
    }
}
</script>
<style lang='less'>
#components-form-demo-advanced-search .ant-form {
    max-width: none;
    margin-top: 24px;
}

.ant-form {
    // width: 570px;
    .ant-form-item {
        .ant-input, .ant-select-selection--single {
            height: 40px;
            border: 1px solid #ECEBEB;
        }
    }
}

</style>

<style lang="less" scoped>
.achieveBasicInfo {
    height: 687px;
    .subTn {
        text-align: center;
        margin-top: 40px;
    }
}
.save_info_btn {
    margin-top: 40px;
    margin-left: 107px;
    width: 250px;
    height: 60px;
    line-height: 60px;
    background: linear-gradient(90deg, #267FEA 0%, #519FF8 100%);
    border-radius: 4px;
    font-size: 22px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #FFFFFF;
}
</style>
